/**
 * 商店界面
 */
class FishShopUI extends UIBase{
    private main_group:eui.Group;
    private btn_close:BaseButton;
    private fish_scroller:eui.Scroller;
    private fish_list:eui.List;
    private _listDataArr:eui.ArrayCollection;

    constructor()
    {
        super('FishShopView');
    }

    public init()
    {
        this.fixIphoneX();
        TujianPrase.instance().getTujianInfo(this.initUI, this);
    }

    public initUI(data:Array<string>)
    {
        this.fish_scroller.viewport.scrollV = 0;

        let fishArr = FishTpl.instance().getDataAsArray();
        let Arr = [];
		let arr = [];
        let hasLockIdList = data;

        for(let k in fishArr)
		{		
			let data = fishArr[k];
			
			if(hasLockIdList.indexOf((parseInt(k)+1).toString()) != -1)
			{
				data['isLocked'] = 0;
			}
			else
			{
				data['isLocked'] = 1;
			}
		}

		//排序 按照是否解锁排 再按id排
		fishArr.sort(function(a, b){
			if(a['isLocked'] == b['isLocked'])
				return a["id"] - b["id"];
			else
				return a['isLocked'] - b['isLocked'];
		});

		for(let k in fishArr)
		{		
			let data = fishArr[k];
			if(arr.length < 2)
			{
				//两个为一组
				arr.push(data);
				if(parseInt(k)+1 == fishArr.length)
				{
					Arr.push(arr);
					arr = [];
				}
			}
			else
			{
				Arr.push(arr);
				arr = [];
				arr.push(data);
			}
		}
        this._listDataArr = new eui.ArrayCollection(Arr);
		this.fish_list.dataProvider = this._listDataArr;
		this.fish_list.itemRenderer = ShopBigItem;
    }

    //屏幕适配x
    protected fixIphoneX()
    {
		if(GlobalManager.instance().isIphonex())
		this.main_group.top = Math.floor(GlobalManager.instance().curHeight()/34);
    }

    public addEvent()
    {
        this.btn_close.addTapHandler(this.close, this);
    }

    public close()
    {
        this.remove(4);
    }

    public removeEvent()
    {
        this.btn_close.removeTapHandler();
    }

    public clear()
    {
        super.clear();
    }
}